import java.time.DayOfWeek;
import java.util.*;

public class Main {
    private Map<String, BadmintonCourt> badmintonCourtMap;
    private List<CustomerAction> actionHistory;

    public void initBadmintonCourt(String name) {

        // 收费标准------------------------------------------------
        // Monday to Friday
        ChargeStandard.WeekdayRangeChargeInfo wrci1 = new ChargeStandard.WeekdayRangeChargeInfo(DayOfWeek.MONDAY, DayOfWeek.FRIDAY, 50);
        wrci1.addTimeRangeChargeInfo(9, 12, 30);
        wrci1.addTimeRangeChargeInfo(12, 18, 50);
        wrci1.addTimeRangeChargeInfo(18, 20, 80);
        wrci1.addTimeRangeChargeInfo(20, 22, 60);

        // Saturday to Sunday
        ChargeStandard.WeekdayRangeChargeInfo wrci2 = new ChargeStandard.WeekdayRangeChargeInfo(DayOfWeek.SATURDAY, DayOfWeek.SUNDAY, 25);
        wrci2.addTimeRangeChargeInfo(9, 12, 40);
        wrci2.addTimeRangeChargeInfo(12, 18, 50);
        wrci2.addTimeRangeChargeInfo(18, 22, 60);

        ChargeStandard cs = new ChargeStandard();
        cs.addWeekdayRangeChargeInfo(wrci1);
        cs.addWeekdayRangeChargeInfo(wrci2);

        // 占用情况--------------------------------------------------
        int min = 9;
        int max = 22;
        CourtOccupation co = new CourtOccupation(min, max);

        BadmintonCourt bc = new BadmintonCourt(name);
        bc.setCharge(cs);
        bc.setOccupation(co);

        this.badmintonCourtMap.put(name, bc);
    }

    public void initSystem() {
        this.badmintonCourtMap = new HashMap<>();
        this.initBadmintonCourt("A");
        this.initBadmintonCourt("B");
        this.initBadmintonCourt("C");
        this.initBadmintonCourt("D");
        this.actionHistory = new ArrayList<>();
    }

    public void printReceiptInfo() {
        System.out.println("> 收入汇总");
        System.out.println("> ---");
        int sum = 0;
        int len = this.badmintonCourtMap.size();
        int count = 0;
        for (BadmintonCourt bc : this.badmintonCourtMap.values()) {
            bc.printCourtReceipt();
            sum += bc.getSumRevenue();
            if (count < len - 1 )
                System.out.println("> ");
            count++;
        }
        System.out.println("> ---");
        System.out.println("> 总计: " + sum);
    }

    public static void main(String[] args) {

        Main main = new Main();
        main.initSystem();
        Scanner sc = new Scanner(System.in);
        String str = null;
        while (!(str = sc.nextLine()).isEmpty()) {
            if (FormatChecker.formatCheckInputString(str)) {
                String[] parts = str.split(" ");
                String courtName = parts[3];
                if (main.badmintonCourtMap.get(courtName) == null) {
                    System.out.println("> Error: the booking is invalid!");
                    continue;
                }

                CustomerAction ca = new CustomerAction();
                ca.parseFromStringInputs(parts);

                main.actionHistory.add(ca);
                boolean retFlag = main.badmintonCourtMap.get(courtName).handleCustomerAction(ca);
                if (!retFlag)
                    continue;

                System.out.println("> Success: the booking is accepted!");
            } else {
                System.out.println("> Error: the booking is invalid!");
            }
        }

        main.printReceiptInfo();
    }
}
